<template>
  <div class="container">
    <div class="top">专题维护</div>
    <div class="box">
      <div class="top1">
        <div class="left">
          <span>标题：</span>
          <el-input v-model="input1" class="first"></el-input>
          <span>是否上架：</span>
          <el-select v-model="value" placeholder="请选择" class="second">
            <el-option
              v-for="item in options"
              :key="item.value"
              :label="item.label"
              :value="item.value"
            ></el-option>
          </el-select>
          <!-- <span>创建/更新日期：</span>
          <el-date-picker v-model="value2" type="date" placeholder="选择日期" class="third"></el-date-picker>-->
          <el-button type="primary" @click="search"  v-show="_SHOWBTN('wzgl-xsxc-zt-ss')">查询</el-button>
          <el-button @click="reset">重置</el-button>
        </div>
        <div class="right">
          <el-button type="primary" @click="add" class="add" v-show="_SHOWBTN('wzgl-xsxc-zt-xj')">+新建</el-button>
        </div>
      </div>
      <!-- 表格 -->
      <el-table
        :data="tableList"
     
        border
        stripe
        :cell-style="changeCellStyle"
        :header-cell-style="rowClass"
      >
        <el-table-column type="index" label="序号" width="52px" align="center"></el-table-column>
        <el-table-column prop="title" label="标题"></el-table-column>

        <el-table-column prop="status" label="是否上架" align="center" width="179px">
          <template slot-scope="scope">
              <el-switch
               v-show="_SHOWBTN('wzgl-xsxc-zt-xiajia')"
              v-model="scope.row.isTrue"
              active-color="#1677FF"
              inactive-color="#E8E8E8"
              @change="userStateChange(scope.row)"
            ></el-switch>
          </template>
        </el-table-column>
        <el-table-column prop="sort" label="排序" align="center" width="171px">
          <template slot-scope="scope">
            <span class="up" @click="up(scope.row.id)">
              <img src="@/assets/image/up.png" alt />
            </span>
            <span class="down" @click="down(scope.row.id)">
              <img src="@/assets/image/down.png" alt />
            </span>
          </template>
        </el-table-column>
        <el-table-column label="操作" align="center" width="223px">
          <template slot-scope="scope">
            <el-button type="primary" size="small" @click="edit(scope.row.id)" class="five" v-show="_SHOWBTN('wzgl-xsxc-zt-xg')">编辑</el-button>
            <!-- 删除 -->
            <SingleDeletion :clearOne="clearOne" :id="scope.row.id" showBetCode="wzgl-xsxc-zt-sc"></SingleDeletion>
          </template>
        </el-table-column>
      </el-table>
    </div>
  </div>
</template>
<script>
import SingleDeletion from "@/components/Popup/SingleDeletion.vue";
export default {
  components: {
     SingleDeletion,
  },
  data() {
    return {
       params: {
        pageNum: 1,
        publishStatus: "",
        title: "",
        pageSize: 10,
      },
      // 表格列表
      tableList: [],
        // 总条数
      total: 0,
      visible: true,
      imageUrl: "",
      // 标题
      input1: "",
      input2: "",
      // 是否上架
      value: "",
      value2: "",
      value3: true,
      currentPage4: 4,
      options: [
        {
          value: "",
          label: "全部",
        },
        {
          value: 5,
          label: "已上架",
        },
        {
          value: 1,
          label: "未上架",
        },
      ],
      ruleForm: {
        name: "",
        classify: "",
        link: ""
      },
      rules: {
        name: [{ required: true, message: "请输入标题", trigger: "blur" }],
        classify: [{ required: true, message: "请输入分类", trigger: "blur" }],
        link: [{ required: true, message: "请输入链接", trigger: "blur" }]
      },
   
    };
  },
   created() {
    this.get();
  },
  methods: {
     // 获取列表
    get() {
      this.Api.specialSearch(this.params).then((res) => {
        if (res.code == 0) {
          this.tableList = res.data;
          this.tableList.map((item) => {
            if (item.publishStatus == 5) {
              this.$set(item, "isTrue", true);
            } else if (item.publishStatus == 1) {
              this.$set(item, "isTrue", false);
            }
          });

          this.total = res.data.total;
        }
      });
    },
   
    // 是否上架状态改变
    userStateChange(row) {
      // 上架
      if (row.isTrue == true) {
        this.Api.specialUp({ id: row.id }).then((res) => {
          if (res.code == 0) {
            return this.$message.success("上架成功");
          } else {
            row.isTrue = !row.isTrue;
            return this.$message.error("上架失败");
          }
        });
      }
      // 下架
      if (row.isTrue == false) {
        this.Api.specialDown({ id: row.id }).then((res) => {
          if (res.code == 0) {
            return this.$message.success("下架成功");
          } else {
            row.isTrue = !row.isTrue;
            return this.$message.error("下架失败");
          }
        });
      }
    },
   // 上移
    up(id) {
       let ID = { id: id };
      this.Api.specialMove1(ID).then((res) => {
        console.log(res);
      this.get()
      });
    },
    // 下移
    down(id) {
      let ID = { id: id };
      this.Api.specialMove(ID).then((res) => {
      this.get()
      });
    }, 
    // 专题搜索
    search(){
      this.Api.specialSearch({
        pageSize: 10,
        pageNum: "1",
        publishStatus: this.value,
        title: this.input1,
      }).then((res) => {
        this.tableList = res.data;
         this.tableList.map((item) => {
            if (item.publishStatus == 5) {
              this.$set(item, "isTrue", true);
            } else if (item.publishStatus == 1) {
              this.$set(item, "isTrue", false);
            }
          });
      });
    },
     // 重置
    reset() {
      (this.value = ""),
       (this.input1 = ""), 
       this.get();
    },
    // 删除
    clearOne(id) {
      let ID = { id: id };
      this.Api.specialDelete(ID).then((res) => {
        if(res.code==0){
          this.$message.success('删除成功')
            this.get();
        }else{
          this.$message.error(res.message)
        }
      
      });
    },
    changeCellStyle(row, column, rowIndex, columnIndex) {
      if (row.column.label === "标题") {
        return "padding-left: 35px"; // 修改的样式
      } else {
        return "";
      }
    },
    rowClass({ row, column, rowIndex, columnIndex }) {
      if (rowIndex === 0 && columnIndex === 1) {
        //指定坐标
        return "padding-left:35px";
      } else {
        return "";
      }
    },
    add() {
      this.$router.push({name:"SpecialXj"});
    },
    edit(id) {
      this.$router.push({name:"SpecialBj",query:{id:id}});
    },
    
   
   
  }
};
</script>
<style lang="less" scoped>
.top {
  width: 1540px;
  height: 68px;
  line-height: 68px;
  color: #333333;
  font-size: 20px;
  border-bottom: 1px solid #dddddd;
  box-sizing: border-box;
}

.top1 {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 35px;
}
.left {
  display: flex;
  margin-top: 19px;
  align-items: center;
}
.right {
  margin-top: 19px;
}
/deep/.left .el-input__inner {
  width: 154px;
  height: 36px;
}
/deep/.left .el-input {
  width: 154px;
}
.left span {
  height: 36px;
  line-height: 36px;
  font-size: 14px;
  color: #333333;
}
.el-button {
  width: 52px;
  height: 36px;
  padding: 0;
}
.five {
  width: 60px;
  height: 28px;
  margin-right: 21px;
}
.first,
.second,
.third {
  margin-right: 20px;
}
/deep/ .add.el-button{
  width: 80px;
}
/deep/.el-pagination {
  white-space: nowrap;
  padding: 2px 5px;
  color: #303133;
  font-weight: 700;
  margin-left: 850px;
  margin-top: 46px;
}
/deep/.el-pagination__jump {
  margin-left: 0;
  font-weight: 400;
  color: #606266;
}
.up {
  margin-right: 23px;
}
/deep/.el-dialog__header {
  padding: 20px 20px 10px;
  background: #e6e9ed;
}
/deep/.el-dialog__wrapper {
  width: 530px;
  height: 100%;
  position: fixed;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  overflow: auto;
}
/deep/.el-form-item__label {
  width: 82px !important;
  text-align: right;
  vertical-align: middle;
  float: left;
  font-size: 14px;
  color: #606266;
  line-height: 40px;
  padding: 0 12px 0 0;
  box-sizing: border-box;
}
/deep/.four .el-input__inner {
  width: 260px;
  height: 36px;
  margin-left: -0px;
}
// 图片上传
/deep/.avatar-uploader .el-upload {
  border: 1px dashed #d9d9d9;
  border-radius: 6px;
  cursor: pointer;
  position: relative;
  overflow: hidden;
  margin-left: 6px;
}
/deep/ .avatar-uploader .el-upload:hover {
  border-color: #409eff;
}
/deep/.avatar-uploader-icon {
  font-size: 28px;
  color: #8c939d;
  width: 88px;
  height: 88px;
  line-height: 88px;
  text-align: center;
}
/deep/.avatar {
  width: 88px;
  height: 88px;
  display: block;
}
.upImg {
  display: flex;
}
.star {
  color: red;
  padding: 0 5px;
}
.tishi {
  width: 360px;
  border-top: 1px solid #dddddd;
  margin-left: 80px;
  padding: 6px 0;
  color: #999999;
  font-size: 12px;
}
/deep/tbody {
  tr {
    height: 45px !important;
    td {
      padding: 0px 0 !important;
    }
  }
  tr td:last-child {
    .cell {
      display: flex;
      justify-content: center;
      align-items: center;
    }
  }
}
/deep/tbody{

    tr td:nth-child(2){
      .cell{
padding-left: 35px;
      }
      
    }

}
</style>